package com.lottery.system.dao.mapper;

import com.lottery.system.dao.dataobject.PrizeDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author: xiaoxie
 * create: 2024-09-06 22:45
 * @BelongsProject: lottery-system
 * @BelongsPackage: com.lottery.system.dao.mapper
 * description: 奖品数据层
 */
@Mapper
public interface PrizeMapper {

    /**
     * @description: 插入奖品数据
     * @author: xiaoxie
     * @date: 2024/9/8 10:31
     * @param: [prizeDO]
     * @return: void
     **/
    @Insert("insert into prize (description,image_url,name,price)" +
            " values (#{description},#{imageUrl},#{name},#{price})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void insert(PrizeDO prizeDO);

    /**
     * @description: 获取奖品总量
     * @author: xiaoxie
     * @date: 2024/9/8 10:31
     * @param: []
     * @return: int
     **/
    @Select("select count(*) from prize")
    int count();

    /**
     * @description: 获取奖品列表
     * @author: xiaoxie
     * @date: 2024/9/8 10:32
     * @param: [offSet, pageSize]
     * @return: java.util.List<com.lottery.system.dao.dataobject.PrizeDO>
     **/
    @Select("select id,image_url,name,price,description from prize order by id desc limit #{offSet},#{pageSize}")
    List<PrizeDO> getprizeList(Integer offSet, Integer pageSize);

    /**
     * @description: 查询列表中存在的奖品id
     * @author: xiaoxie
     * @date: 2024/9/9 11:42
     * @param: [prizeIds]
     * @return: java.util.List<java.lang.Long>
     **/
    @Select("<script>" +
            " select id from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<Long> exitsPrizeIds(@Param(value = "items") List<Long> prizeIds);

    /**
     * @description: 根据id列表查询奖品信息
     * @author: xiaoxie
     * @date: 2024/9/9 19:20
     * @param: [prizeIds]
     * @return: java.util.List<com.lottery.system.dao.dataobject.PrizeDO>
     **/
    @Select("<script>" +
            " select id,description,image_url,name,price from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<PrizeDO> selectListByIds(@Param(value = "items") List<Long> prizeIds);

    /**
     * @description: 通过奖品id查询奖品信息
     * @author: xiaoxie
     * @date: 2024/9/13 10:47
     * @param: [prizeId]
     * @return: com.lottery.system.dao.dataobject.PrizeDO
     **/
    @Select("select id,description,image_url,name,price " +
            " from prize where id = #{id}")
    PrizeDO selectById(@Param(value = "id") Long id);
}
